package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.model.User;
import com.zr.service.StudentServiceHyx;
import com.zr.service.TeacherServiceHyx;
import com.zr.serviceImpl.StudentServiceImplHyx;
import com.zr.serviceImpl.TeacherServiceImplHyx;

public class cxStudentSnameTidControllerHyx extends HttpServlet{

	StudentServiceHyx sService = new StudentServiceImplHyx();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		PrintWriter pw = resp.getWriter();
		HttpSession sesion = req.getSession();
		User u = (User) sesion.getAttribute("User");
		String sname = req.getParameter("ssname");
		int sid =0;
		if(sname.matches("[0-9]+")){
		sid =Integer.parseInt(req.getParameter("ssname"));
		}
		int count = sService.countStudentBySname(u.getTid(), sid, sname);
		if(count>0){//判断相同用户名个数是否大于0
			pw.write("1");
		}else{
			pw.write("0");
		}
		pw.flush();
		pw.close();
	}
}
